﻿/*
* edirauth - http://edirauth.codeplex.com
* A .NET library and utility for authenticating to eDirectory
* Copyright (c) 2013 Matt Shirilla (http://shirilla.com)
* Licensed under the Microsoft Public License (MS-RL)
* http://edirauth.codeplex.com/license
*/

using Novell.Directory.Ldap;

namespace edirAuth
{
    public class AuthInfo
    {
        internal LdapResult passwordResult = new LdapResult();
        internal LdapResult bindResult = new LdapResult();
        internal LdapResult dnLookupResult = new LdapResult();
        internal LdapResult loginDisabledResult = new LdapResult();
        internal LdapResult lockedByIntruderResult = new LdapResult();
        internal LdapResult expiredResult = new LdapResult();
        internal LdapEntry ldapEntry;
        internal string attrValue;


        public AuthInfo() { }

        public bool allowLogin {
            get {
                if (passwordResult.Code == 0 && bindResult.Code == 0 && dnLookupResult.Code == 0 &&
                loginDisabledResult.Code == 0 && lockedByIntruderResult.Code == 0 && expiredResult.Code == 0)
                    return true;
                else
                    return false;
            }
        }

        public AuthInfo(string attrValue) {
            this.attrValue = attrValue;
        }

        internal void setBindResults(int code, string description) {
            this.bindResult.Code = code;
            this.bindResult.Desc = description;
        }

        internal void setDnlookupResults(int code, string description) {
            this.dnLookupResult.Code = code;
            this.dnLookupResult.Desc = description;
        }

        internal void setPasswordResults(int code, string description) {
            this.passwordResult.Code = code;
            this.passwordResult.Desc = description;
        }

        internal void setLoginDisabledLookupResult(int code, string description) {
            this.loginDisabledResult.Code = code;
            this.loginDisabledResult.Desc = description;
        }

        internal void setLockedByIntruderLookupResult(int code, string description) {
            this.lockedByIntruderResult.Code = code;
            this.lockedByIntruderResult.Desc = description;
        }

        internal void setExpiredResult(int code, string description) {
            this.expiredResult.Code = code;
            this.expiredResult.Desc = description;
        }

        public string ToConsoleString() {
            string template = "allowLogin: {0}\r\nbindResults: {1}\r\nDNlookupResults: {2}\r\nPasswordResults: {3}\r\nloginDisabledResult: {4}\r\nlockedByIntruderResult: {5}\r\nexpiredResult: {6}";
            string output = string.Format(template,
                                          allowLogin,
                                          bindResult.ToConsoleString(),
                                          dnLookupResult.ToConsoleString(),
                                          passwordResult.ToConsoleString(),
                                          loginDisabledResult.ToConsoleString(),
                                          lockedByIntruderResult.ToConsoleString(),
                                          expiredResult.ToConsoleString()
                                          );
            return output;
        }

        public LdapResult PasswordResult {
            get { return passwordResult; }
        }

        public LdapResult BindResult {
            get { return bindResult; }
        }

        public LdapResult DNLookupResult {
            get { return dnLookupResult; }
        }

        public LdapResult LoginDisabledResult {
            get { return loginDisabledResult; }
        }

        public LdapResult LockedByIntruderResult {
            get { return lockedByIntruderResult; }
        }

        public LdapResult ExpiredResult {
            get { return expiredResult; }
        }

        public LdapEntry LdapEntry {
            get { return ldapEntry; }
        }


    }//class
}//namespace
